<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    //sort 
    //作用：数组排序
    //返回：排序后的新数组
    const arr = [49, 5, 14, 89, 71, 3, 10];
    arr.sort((a,b)=>a-b)//升序
    console.log(arr);
    arr.sort((a,b)=>b-a)//降序
    console.log(arr);

    //对象数组的排序:sort() 方法除了可以用于数字数组和字符数组的排序外，还可用于对象数组的排序
    const arr1=[
      {uname:'张三',age:18},
      {uname:'李四',age:14},
      {uname:'哈哈',age:15},
      {uname:'呵呵',age:3},
    ]
    arr1.sort((a,b)=>a.age-b.age)
    console.log(arr1);
  </script>
</body>
</html>